<script type="text/javascript">
    $(document).ready(function() {
        $("#activity_checkAll").click(function() {
            if ($(this).attr("checked") == "checked") {
                $(":checkbox").attr("checked", true);
            } else {
                $(":checkbox").attr("checked", false);
            }
        });

    });
</script> 
<legend>
    <h4>
        <?php
        echo $control->getAjaxLink(array('name' => '功能列表', 'id' => 'showEventList'), array(
            'cooker' => 'BAEvent@showEventList'
        ));
        ?>\
        <?php
        echo $control->getAjaxLink('代金券类型', array(
            'cooker' => 'BAVoucher@showVoucherTypeList'
        ));
        ?>\
        代金券列表
        <?php
        //$voucherTypeAlias = $voucherType->getValue();
        //echo $voucherTypeAlias;
        ?>
    </h4>
</legend>
<fieldset>
    <table class="table table-hover">
        <thead>
            <tr>
                <th><input type="checkbox" name="activity_checkAll" id="activity_checkAll"></th>
                <th>编号</th>
                <th>类型</th>
                <th>姓名</th>
                <th>许可类型</th>
                <th>有效期至</th>                
                <th>操作</th>
            </tr> 
        </thead>
        <tbody>
            <?php
            $voucherCooker = new BCafeVoucherCooker();
            $userCooker = new BAUserCooker();
            $permitCooker = new BAPermitCooker();

            foreach ($voucherView as $id => $list) {
                $userInfoId = $list->getItem('userInfoId')->getValue();
                $voucherId = $list->getItem('voucherId')->getValue();
                $voucherTypeId = $list->getItem('voucherTypeId')->getValue();
                $permitId = $list->getItem('permitId')->getValue();
                $voucherType = $voucherCooker->getVoucherType($voucherTypeId);
                $userInfo = $userCooker->getUserInfo($userInfoId);
                $oPermit = $permitCooker->getPermit($permitId);
                //$voucher = $voucherCooker->getVoucher($voucherId);
                $voucherTypeAlias = $voucherType->getValue();
                /*
                $after10year = strtotime("+10 years");
                $expire = $oPermit->getItem('expireTime')->getValue();
                if ($expire > $after10year) {
                    $expireTime = '10年后';
                } else {
                    $expireTime = date('Y/m/d:H', $expire);
                }
                 * 
                 */
                $expireTime = $voucherCooker->getExpireTime($list);
                if($expireTime!=NULL){
                    $expireTime = date('Y/m/d', $expireTime);
                }

                $name = '---';
                if ($userInfo != NULL) {
                    if ($userInfo->getItem('familyName') != NULL) {
                        $name = $userInfo->getItem('familyName')->getValue();
                    }
                    if ($userInfo->getItem('surName') != NULL) {
                        $surName = $userInfo->getItem('surName')->getValue();
                        if ($name == '---')
                            $name = $surName;
                        else {
                            $name.=$surName;
                        }
                    }
                }
                $permitType = $permitCooker->getPermitTypeByPermit($oPermit);
                $permitAlias = '--';
                if ($permitType != NULL) {
                    $permitTypeAlias = $permitType->getValue();
                }
                ?>
                <tr>
                    <td><label class="checkbox">
                            <input type="checkbox" name="subBox[]" value="<?php echo $id; ?>"> 
                        </label></td>
                    <td> <?php echo $voucherId; ?> </td>
                    <td> <?php echo $voucherTypeAlias; ?> </td>
                    <td> <?php echo $name; ?> </td>
                    <td> <?php echo $permitTypeAlias; ?></td>
                    <td> <?php echo $expireTime; ?> </td>
                    <td>
                        <div class="row-fluid">
                            <?php
                            echo $control->getLink('查看', array(
                                'cooker' => 'BAVoucher@showVoucher',
                                'voucherId' => $id
                            ));
                            ?>
                        </div>                   
                    </td>
                </tr>
            <?php }
            ?>
        </tbody>
    </table>
    <div class="pagination">  
        <ul>  
            <li class="active">
                <a href="javascript:void()">前一页</a>    </li>  
            <li class="active">
                <a href="javascript:void()">1</a>    </li>  
            <li class="active">
                <a href="javascript:void()">后一页</a>    </li>  
        </ul>  
    </div>
